$(document).ready(function(){
	loadZoneStart();
	loadZoneEnd();
});

function loadZoneStart() {
	$.ajax({
		url : "CS43004Srvl", 
		type : "POST",
		data : {
			process_type: "getZone"
		},
	//	anync:false,
		dataType:"JSON",
		success: function(data){
			var selected="";
			var options = '';
			options += '<option value="">-- เลือกเขต --</option>';
			for (var i = 0; i < data.values.length; i++) {
				options += '<option value="' + data.values[i] + '" '+selected+'>' + data.messages[i] +  '</option>';
			}
			$("select[name=zone_start]#inputZoneStart").html(options);
		}
	});
}

function loadZoneEnd() {
	$.ajax({
		url : "CS43004Srvl", 
		type : "POST",
		data : {
			process_type: "getZone" 
		},
	//	anync:false,
		dataType:"JSON",
		success: function(data){
			var selected="";
			var options = '';
			options += '<option value="">-- เลือกเขต --</option>';
			for (var i = 0; i < data.values.length; i++) {
				options += '<option value="' + data.values[i] + '" '+selected+'>' + data.messages[i] +  '</option>';
			}
			$("select[name=zone_end]#inputZoneEnd").html(options);
		}
	});
}

function printReport() {
	
	var vaZoneStart = $("#inputZoneStart").val();
	var vaZoneEnd = $("#inputZoneEnd").val();
	var vaFromDate = $("#datetimepicker1").val();
	var vaToDate = $("#datetimepicker2").val();
	var vaReportType = $("#inputReportType").val();
	var vnUserId = $("#userId").val();
	var vnSiteId = $("#siteId").val();
	
	if(vaZoneStart.trim().length == 0 || vaZoneEnd.trim().length == 0 || vaFromDate.trim().length == 0 
			|| vaToDate.trim().length == 0 || vaReportType.trim().length == 0)
	{
		$("#modal_content").html("กรุณากรอกข้อมูลให้ครบถ้วน");
		$("#warningModal").modal();
		return;
	}else{
		var url = reporturl;
		
		if(vaReportType == "bill_amount"){
			url = url+"CS43005R.jsp";
		} else if(vaReportType == "garbage_charge"){
			url = url+"CS43006R.jsp";
		} else if(vaReportType == "wastewater_charge"){
			url = url+"CS43007R.jsp";
		} else if(vaReportType == "other_charge"){
			url = url+"CS43008R.jsp";
		} else if(vaReportType == "total_amount"){
			url = url+"CS43009R.jsp";
		} 

		url = url+"?datefrom="+vaFromDate+"&dateto="+vaToDate+"&siteid="+vnSiteId+"&userid="+vnUserId+"&zonefrom="+vaZoneStart+"&zoneto="+vaZoneEnd;
		
		window.open(url);
	}
	
	
}